#!/usr/bin/env python
# -*- coding: utf-8 -*-

'''
Author: Bruno Alves 
Date: 2012/02/10
Version: v1.0
'''

import csv
import time



class Csv:
 
    def __init__(self):
        pass
 
    def DataFileSearch(self, file_name, data_list, structure):
        
        if structure == 1:
            print 'Loading CSV Files...'
            timei = time.clock()
            file = csv.writer(open(file_name, 'wb'), delimiter=',')
            for row in data_list:
                file.writerow([row[2],row[1].encode('utf-8'),row[0].encode('utf-8')])
                pass
            timef = time.clock()
            print 'Time Elasped =', timef-timei
            print 'Finished'         
            pass
        
        elif structure == 2:
            print 'Loading CSV Files...'
            timei = time.clock()
            file = csv.writer(open(file_name, 'wb'), delimiter=',')
            for row in data_list:
                file.writerow([row[2],row[1].encode('utf-8'),row[0]])
                pass
            timef = time.clock()
            print 'Time Elasped =', timef-timei
            print 'Finished'              
            pass
        
        elif structure == 3:
            print 'Loading CSV Files...'
            timei = time.clock()
            file = csv.writer(open(file_name, 'wb'), delimiter=',')
            for row in data_list:
                file.writerow([row[3],row[2].encode('utf-8'),row[1].encode('utf-8'),row[0].encode('utf-8')])
                pass
            timef = time.clock()
            print 'Time Elasped =', timef-timei
            print 'CSV OK'            
            pass
        
        elif structure == 4:
            print 'Loading CSV Files...'
            timei = time.clock()
            file = csv.writer(open(file_name, 'wb'), delimiter=',')
            for row in data_list:
                file.writerow([row[3],row[2].encode('utf-8'),row[1].encode('utf-8'),row[0]])
                pass
            timef = time.clock()
            print 'Time Elasped =', timef-timei
            print 'CSV OK'
            pass
        
        elif structure == 5:
            print 'Loading CSV Files...'
            timei = time.clock()
            file = csv.writer(open(file_name, 'wb'), delimiter=',')
            for row in data_list:
                file.writerow([row[3],row[2].encode('utf-8'),row[1].encode('utf-8'),row[0].encode('utf-8')])
                pass
            timef = time.clock()
            print 'Time Elasped =', timef-timei 
            print 'CSV OK'            
            pass
        
        elif structure == 6:
            print 'Loading CSV Files...'
            timei = time.clock()
            file = csv.writer(open(file_name, 'wb'), delimiter=',')
            for row in data_list:
                file.writerow([row[3],row[2].encode('utf-8'),row[1].encode('utf-8'),row[0]])
                pass
            timef = time.clock()
            print 'Time Elasped =', timef-timei
            print 'Finished'             
            pass

   
    def HTMLTagFile(self, file_name, data_label, data_values):

        print 'Loading CSV Files...'
        file = csv.writer(open(file_name, 'wb'), delimiter=',')
        index = 0
        for row in data_label:

            file.writerow([row,data_values[int(index)]])
            index += 1
            pass
        print 'Finished!!!'

